/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.Produccion;
import Atxy2k.CustomTextField.RestrictedTextField;
import Controlador.Bean.Produccion.Receta;
import Controlador.Bean.Produccion.Fase;
import Controlador.Bean.Produccion.ProductoxFase;
import gui.General.Main;
import javax.swing.JOptionPane;
import lib.Validaciones;
/**
 *
 * @author Nadhia
 */
public class detalleProductoEmpaquetado extends javax.swing.JPanel {

    /**
     * Creates new form detalleProductoEmpaquetado
     */
    Receta nr;
    AjusteReceta aj;
    public detalleProductoEmpaquetado(Receta nr, AjusteReceta aj) {
        this.nr = nr;
        this.aj = aj;
        initComponents();
        initComp2();
    }
    private void initComp2(){
//         setTb2(new TableModel2());
//         tblIngredientes.setModel(getTb2());
//         tblIngredientes.setRowSelectionAllowed(true);
            txtNombre2.setText(nr.getNombre());
             txtNombre2.setEnabled(false);
             txtIdFase2.setEnabled(false);
             RestrictedTextField restricted = new RestrictedTextField(txtHorasH2);
         restricted.setLimit(5);
//         restricted.setOnlyNums(true);
         restricted = new RestrictedTextField(txtHorasM2);
         restricted.setLimit(5);
//         restricted.setOnlyNums(true);
//         tblProductos.setModel(tb);
//         tblProductos.setRowSelectionAllowed(true);
//         txtIdProducto.setEditable(false);
//         tipos = Controlador.Service.Almacen.GestionAlmacenes.obtenerTipo();
//         cmbTipo.removeAllItems();
//         cmbUnidadMedida.removeAllItems();
//         cmbUnidadMedida.addItem("Seleccionar");
//         cmbUnidadMedida.addItem("Kg.");
//         cmbUnidadMedida.addItem("m.");
//         cmbUnidadMedida.addItem("gr.");
//         cmbUnidadMedida.addItem("Unidades");
//         cmbTipo.addItem("Seleccionar");
//         for(int i=0; i<tipos.size(); i++){
//             cmbTipo.addItem(tipos.get(i).getNombre());
//         }
//         tblProductos.setDefaultRenderer(JButton.class, new MiRender());
//         tblProductos.setDefaultEditor( JButton.class, new MiEditor());
//         btnBuscar.setMnemonic(KeyEvent.VK_F2);
     }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        txtNombre2 = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        txtHorasH2 = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        txtHorasM2 = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtDescripcion2 = new javax.swing.JTextArea();
        txtIdFase2 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        btnContinuar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        btnSeleccionar = new javax.swing.JButton();
        btnDetalle = new javax.swing.JButton();

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Empaquetado"));
        jPanel4.setAutoscrolls(true);
        jPanel4.setPreferredSize(new java.awt.Dimension(730, 200));

        jLabel11.setText("Nombre Producto:");

        jLabel12.setText("Preparación (horas):");

        txtNombre2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNombre2ActionPerformed(evt);
            }
        });

        jLabel19.setText("Horas Hombre (horas):");

        txtHorasH2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtHorasH2ActionPerformed(evt);
            }
        });

        jLabel20.setText("Indicaciones:");

        txtHorasM2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtHorasM2ActionPerformed(evt);
            }
        });

        txtDescripcion2.setColumns(20);
        txtDescripcion2.setRows(5);
        jScrollPane3.setViewportView(txtDescripcion2);

        txtIdFase2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdFase2ActionPerformed(evt);
            }
        });

        jLabel13.setText("Id Fase:");

        btnContinuar.setText("Guardar");
        btnContinuar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnContinuarActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Receta"));

        btnSeleccionar.setText("Seleccionar Ingrediente");
        btnSeleccionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSeleccionarActionPerformed(evt);
            }
        });

        btnDetalle.setText("Ver Detalle");
        btnDetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDetalleActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(72, 72, 72)
                .addComponent(btnSeleccionar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnDetalle)
                .addGap(100, 100, 100))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(btnSeleccionar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnDetalle))
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnContinuar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addContainerGap(80, Short.MAX_VALUE)
                                        .addComponent(jLabel13))
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel11))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                        .addContainerGap(21, Short.MAX_VALUE)
                                        .addComponent(jLabel12)))
                                .addGap(18, 18, 18))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel19)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNombre2, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtHorasH2, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtHorasM2, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtIdFase2, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(79, 79, 79)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel20)
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(btnCancelar)))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel20)
                            .addComponent(txtIdFase2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13))
                        .addGap(19, 19, 19)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNombre2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtHorasH2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel19))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtHorasM2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnContinuar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 673, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    public int validar(){
        int error = 0;
        boolean vali1 = Validaciones.validarReal(txtHorasH2.getText());
        boolean vali2 = Validaciones.validarReal(txtHorasM2.getText());
        if(txtHorasH2.getText().isEmpty()) {
            error=2;
        }
        else
           if(!vali1){
            error=1;}
           else 
            if (txtHorasM2.getText().isEmpty()){
                error=4;
            }
            else
            if(!vali2){
            error=3;}    
                
            
        
//        int indice = (int)cmbTipo.getSelectedIndex();
//        System.out.println("indice...."+indice);
//        System.out.println("fecha...."+jdpFecha.getDate());
//        if(txtNombre.getText().isEmpty()){
//        error=1;}
//        else if((jdpFecha.getDate()== null) || (jdpFecha.getDate().after(today))){
//        error=2; }
//        else if((indice==0))
//        { error=3;  }
//        else if(txtDescripcion.getText().isEmpty()){
////        error=4;    
//        }
        
        
        
        return error;
        
        
    }
    
    private void btnDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetalleActionPerformed

        // TODO add your handling code here:
        if(txtIdFase2.getText().isEmpty()){
            JOptionPane.showMessageDialog(this,"Debe ingresar ingredientes", "Advertencia", JOptionPane.OK_OPTION);

        }
        else{
            //            Controlador.Service.Produccion.GestionProduccion.actualizarFase(fa);
            //            JOptionPane.showMessageDialog(this,"Se actualizo datos");
            Fase fa = new Fase(txtIdFase2.getText(), nr.getIdReceta(), "Empaquetado", 4, Double.parseDouble(txtHorasH2.getText()), txtDescripcion2.getText(),"1",Double.parseDouble(txtHorasM2.getText()),"TMA000004");
            buscarIngrediente bi = new buscarIngrediente(fa.getIdFase());
            Main.getDesktop().add(bi);
            bi.setVisible(true);
            //            System.out.println("efectua la actualización");
        }
    }//GEN-LAST:event_btnDetalleActionPerformed

    private void btnSeleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSeleccionarActionPerformed
        //        Fase fa = new Fase(txtIdFase2.getText(), nr.getIdReceta(), "Decorado", 3, Double.parseDouble(txtHorasH2.getText()), txtDescripcion2.getText(),"1",Double.parseDouble(txtHorasM2.getText()),"TMA000003");
        try {

        int error = validar();  
           
           if(error==1){
           JOptionPane.showMessageDialog(this,"Horas hombre debe ser número real", "Advertencia", JOptionPane.OK_OPTION);
               
           }
           else 
           if(error==2){
               JOptionPane.showMessageDialog(this,"Ingrese Horas hombre", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
           }
            else
               if(error==3){
           JOptionPane.showMessageDialog(this,"Preparación debe serser número real", "Advertencia", JOptionPane.OK_OPTION);
               
           }
           else 
           if(error==4){
               JOptionPane.showMessageDialog(this,"Ingrese Preparación", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
           }
            //               if(vseleccionfases.isEmpty()){
                //               JOptionPane.showMessageDialog(this,"Selecciona mínimo un proceso", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
                //           }
            //           else
            //            if(error==4){
                //               JOptionPane.showMessageDialog(this,"Ingrese una descripcion");
                //           }
            else
            if(error==0){
                //         System.out.println("dato.."+cmbTipo.getSelectedIndex());
                //System.out.println("dato.."+cmbTipo.getSelectedIndex()-1);

                //        agregar receta
                //        Double.parseDouble(txtCantidadProducto.getText())
                Fase fa = new Fase(txtIdFase2.getText(), nr.getIdReceta(), "Empaquetado", 4, Double.parseDouble(txtHorasH2.getText()), txtDescripcion2.getText(),"1",Double.parseDouble(txtHorasM2.getText()),"TMA000004");

                //        Receta re = new Receta(txtIdReceta.getText(), idBuscar, nombreBuscar, Double.parseDouble(txtCantidadProducto.getText()), " ", txtDescripcion.getText(), "1");
                //        Receta re = new Receta(" ", idBuscar, nombreBuscar, 43.4, " ", "hola mundo", "1");

                if(txtIdFase2.getText().isEmpty()){

                    try {
                        Controlador.Service.Produccion.GestionProduccion.agregarFase(fa);
                        txtIdFase2.setText(fa.getIdFase());
                        //            Controlador.Service.Produccion.GestionProduccion.agregarReceta(re);
                        System.out.println("efectua la insercion");
                        //            JOptionPane.showMessageDialog(this,"Se ingreso datos");
                        //        para continuar siguiente ventana

                        agregarIngredientePI aip = new agregarIngredientePI(nr,fa);
                        Main.getDesktop().add(aip);
                        aip.setVisible(true);

                        //            AjusteReceta arp = new AjusteReceta( seleccionfases,re);
                        //             Main.getDesktop().add(arp);
                        //        ar.actualizar(seleccionfases);

                        //        arp.setVisible(true);
                        //        this.dispose();

                    } catch (Exception ex) {
                        System.out.println("nno guarda");
                    }

                }
                else{
                    Controlador.Service.Produccion.GestionProduccion.actualizarFase(fa);
                    agregarIngredientePI aip = new agregarIngredientePI(nr,fa);
                    Main.getDesktop().add(aip);
                    aip.setVisible(true);
                    //            JOptionPane.showMessageDialog(this,"Se actualizo datos");
                }

                //
                //        fecha = jdpFecha.getDate();
                //        Maquina nm = new Maquina(txtIdMaquina.getText(), txtNombre.getText(),  tipos.get(cmbTipo.getSelectedIndex()-1).getIdTipoMaquina(),  txtDescripcion.getText() , fecha, "1", "1" );
                //
                //
                //         tb.actualizarTabla();
                //        txtIdMaquina.setText("");
                //        txtNombre.setText("");
                //        txtDescripcion.setText("");
                //        cmbTipo.setSelectedIndex(0);
                //        cmbTipo.setEnabled(true);
            }

            //        dpFecha.setDate(today);

        } catch (Exception ex) {
            System.out.println("errror"+ex.getMessage());
            System.out.println("errror"+ex);
        }

    }//GEN-LAST:event_btnSeleccionarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        int confirmado = JOptionPane.showConfirmDialog(this,"¿Desea cancelar el producto?");
        if (confirmado == JOptionPane.OK_OPTION){
            //              JOptionPane.showMessageDialog(this,"Se actualizo datos");  Controlador.Service.Produccion.GestionProduccion.eliminarProductoxFase((String)tblProductos.getValueAt(selectedRowIndex, 0), fa.getIdFase());
            //                JOptionPane.showMessageDialog(this,"No se puede eliminar Ingredientes, crear nueva receta");

            //                agregarProducto  ap = new agregarProducto(ar, (String)tblProductos.getValueAt(selectedRowIndex, 0),(String)tblProductos.getValueAt(selectedRowIndex, 1));
            //                Main.getDesktop().add(ap);
            //                ap.setVisible(true);
            String codigoR = nr.getIdReceta();
            Controlador.Service.Produccion.GestionProduccion.cambiarEstadoReceta(codigoR);
            aj.dispose();
            //                this.dispose();
            //                Controlador.Service.Almacen.GestionAlmacenes.eliminarProductos((String)tblProductos.getValueAt(selectedRowIndex, 0));
            //                tb.actualizarTabla();
        }

        txtIdFase2.setText("");
        txtNombre2.setText("");
        txtDescripcion2.setText("");
        txtHorasH2.setText("");
        txtHorasM2.setText("");
        //            JOptionPane.showMessageDialog(this,"Cerrar Ventana Producto Final", "Advertencia", JOptionPane.OK_OPTION);

    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnContinuarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnContinuarActionPerformed
        // TODO add your handling code here:
        try {

            int error = validar();
            if(txtIdFase2.getText().isEmpty()){
                JOptionPane.showMessageDialog(this,"Debe ingresar ingredientes", "Advertencia", JOptionPane.OK_OPTION);
            }
            else
            if(error==1){
                JOptionPane.showMessageDialog(this,"Horas hombre debe ser número real", "Advertencia", JOptionPane.OK_OPTION);

            }
            else
            if(error==2){
                JOptionPane.showMessageDialog(this,"Ingrese Horas hombre", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
            }
            else
            if(error==3){
                JOptionPane.showMessageDialog(this,"Preparación Masa debe ser número real", "Advertencia", JOptionPane.OK_OPTION);

            }
            else
            if(error==4){
                JOptionPane.showMessageDialog(this,"Ingrese Preparación Masa", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
            }
            //               if(vseleccionfases.isEmpty()){
                //               JOptionPane.showMessageDialog(this,"Selecciona mínimo un proceso", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
                //           }
            //           else
            //            if(error==4){
                //               JOptionPane.showMessageDialog(this,"Ingrese una descripcion");
                //           }
            else
            if(error==0){
                //         System.out.println("dato.."+cmbTipo.getSelectedIndex());
                //System.out.println("dato.."+cmbTipo.getSelectedIndex()-1);

                //        agregar receta
                //        Double.parseDouble(txtCantidadProducto.getText())
                //        Fase fa = new Fase(txtIdFase.getText(), nr.getIdReceta(), "Horneado", 1, Double.parseDouble(txtHorasH.getText()), txtDescripcion.getText(),"1",Double.parseDouble(txtHorasM.getText()),"TMA000001");
                Fase fa = new Fase(txtIdFase2.getText(), nr.getIdReceta(), "Empaquetado", 4, Double.parseDouble(txtHorasH2.getText()), txtDescripcion2.getText(),"1",Double.parseDouble(txtHorasM2.getText()),"TMA000004");

                //                Receta re = new Receta(txtIdReceta.getText(), idBuscar, nombreBuscar, Double.parseDouble(txtCantidadProducto.getText()), " ", txtDescripcion.getText(), "1");
                //        Receta re = new Receta(" ", idBuscar, nombreBuscar, 43.4, " ", "hola mundo", "1");
                Controlador.Service.Produccion.GestionProduccion.actualizarFase(fa);
                //            JOptionPane.showMessageDialog(this,"Se actualizo datos");
                System.out.println("efectua la actualización");
                ProductoxFase prxfa = new ProductoxFase(nr.getIdProducto(), fa.getIdFase(), "S", Double.parseDouble("1"), "1");
                try {

                    Controlador.Service.Produccion.GestionProduccion.agregarProductoxFase(prxfa);
                    JOptionPane.showMessageDialog(null,"Se creó la receta con sus fases");

                    String codigo = nr.getIdProducto();
                    Controlador.Service.Produccion.GestionProduccion.cambiarEstado(codigo);
                    aj.dispose();
                } catch (Exception ex) {

                }

                //        if(txtIdFase.getText().isEmpty()){
                    //
                    //          try {
                        //            Controlador.Service.Produccion.GestionProduccion.agregarFase(fa);
                        //            txtIdFase.setText(fa.getIdFase());
                        ////            Controlador.Service.Produccion.GestionProduccion.agregarReceta(re);
                        //            System.out.println("efectua la insercion");
                        ////            JOptionPane.showMessageDialog(this,"Se ingreso datos");
                        //            //        para continuar siguiente ventana
                        //
                        ////            agregarIngrediente aip = new agregarIngrediente(nr,fa);
                        ////            Main.getDesktop().add(aip);
                        ////            aip.setVisible(true);
                        //
                        ////            AjusteReceta arp = new AjusteReceta( seleccionfases,re);
                        ////             Main.getDesktop().add(arp);
                        ////        ar.actualizar(seleccionfases);
                        //
                        ////        arp.setVisible(true);
                        ////        this.dispose();
                        //
                        //        } catch (Exception ex) {
                        //            System.out.println("nno guarda");
                        //        }
                    //
                    //        }
                //        else{
                    //            Controlador.Service.Produccion.GestionProduccion.actualizarFase(fa);
                    ////            JOptionPane.showMessageDialog(this,"Se actualizo datos");
                    //            System.out.println("efectua la insercion");
                    //        }

                //
                //        fecha = jdpFecha.getDate();
                //        Maquina nm = new Maquina(txtIdMaquina.getText(), txtNombre.getText(),  tipos.get(cmbTipo.getSelectedIndex()-1).getIdTipoMaquina(),  txtDescripcion.getText() , fecha, "1", "1" );
                //
                //
                //         tb.actualizarTabla();
                //        txtIdMaquina.setText("");
                //        txtNombre.setText("");
                //        txtDescripcion.setText("");
                //        cmbTipo.setSelectedIndex(0);
                //        cmbTipo.setEnabled(true);
            }

            //        dpFecha.setDate(today);

        } catch (Exception ex) {
            System.out.println("errror"+ex.getMessage());
            System.out.println("errror"+ex);
        }
    }//GEN-LAST:event_btnContinuarActionPerformed

    private void txtIdFase2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIdFase2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIdFase2ActionPerformed

    private void txtHorasM2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtHorasM2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHorasM2ActionPerformed

    private void txtHorasH2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtHorasH2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHorasH2ActionPerformed

    private void txtNombre2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNombre2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNombre2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnContinuar;
    private javax.swing.JButton btnDetalle;
    private javax.swing.JButton btnSeleccionar;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextArea txtDescripcion2;
    private javax.swing.JTextField txtHorasH2;
    private javax.swing.JTextField txtHorasM2;
    private javax.swing.JTextField txtIdFase2;
    private javax.swing.JTextField txtNombre2;
    // End of variables declaration//GEN-END:variables
}
